{% extends 'base.html' %}
{% load crispy_forms_tags %}

{% block title %}注册 - 校园技能交换平台{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title mb-0">用户注册</h4>
            </div>
            <div class="card-body">
                {% if form.errors %}
                <div class="alert alert-danger">
                    <h5 class="alert-heading">注册信息有误：</h5>
                    <ul class="mb-0">
                        {% for field, errors in form.errors.items %}
                            {% for error in errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        {% endfor %}
                    </ul>
                </div>
                {% endif %}

                <form method="post" novalidate>
                    {% csrf_token %}
                    <div class="row">
                        <div class="col-md-6">
                            <h5 class="mb-3">账号信息</h5>
                            <div class="mb-3">
                                <label for="{{ form.username.id_for_label }}" class="form-label">用户名</label>
                                {{ form.username }}
                                {% if form.username.errors %}
                                <div class="invalid-feedback d-block">{{ form.username.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.password1.id_for_label }}" class="form-label">密码</label>
                                {{ form.password1 }}
                                {% if form.password1.errors %}
                                <div class="invalid-feedback d-block">{{ form.password1.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.password2.id_for_label }}" class="form-label">确认密码</label>
                                {{ form.password2 }}
                                {% if form.password2.errors %}
                                <div class="invalid-feedback d-block">{{ form.password2.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.email.id_for_label }}" class="form-label">电子邮箱</label>
                                {{ form.email }}
                                {% if form.email.errors %}
                                <div class="invalid-feedback d-block">{{ form.email.errors.0 }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="col-md-6">
                            <h5 class="mb-3">个人信息</h5>
                            <div class="mb-3">
                                <label for="{{ form.user_type.id_for_label }}" class="form-label">用户类型</label>
                                {{ form.user_type }}
                                {% if form.user_type.errors %}
                                <div class="invalid-feedback d-block">{{ form.user_type.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.student_id.id_for_label }}" class="form-label">学号/工号</label>
                                {{ form.student_id }}
                                {% if form.student_id.errors %}
                                <div class="invalid-feedback d-block">{{ form.student_id.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.college.id_for_label }}" class="form-label">学院</label>
                                {{ form.college }}
                                {% if form.college.errors %}
                                <div class="invalid-feedback d-block">{{ form.college.errors.0 }}</div>
                                {% endif %}
                            </div>

                            <div class="mb-3">
                                <label for="{{ form.major.id_for_label }}" class="form-label">专业/部门</label>
                                {{ form.major }}
                                {% if form.major.errors %}
                                <div class="invalid-feedback d-block">{{ form.major.errors.0 }}</div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-3">
                        <h5>其他信息</h5>
                        <div class="mb-3">
                            <label for="{{ form.bio.id_for_label }}" class="form-label">个人简介</label>
                            {{ form.bio }}
                            {% if form.bio.errors %}
                            <div class="invalid-feedback d-block">{{ form.bio.errors.0 }}</div>
                            {% endif %}
                        </div>
                    </div>

                    <div class="alert alert-info mt-3">
                        <h5 class="alert-heading">注册须知：</h5>
                        <ul class="mb-0">
                            <li>用户名长度为3-20个字符，只能包含字母、数字和下划线</li>
                            <li>密码长度至少为8位，不能太简单</li>
                            <li>请使用真实的学校邮箱，方便找回密码</li>
                            <li>请填写真实的学号/工号，方便身份验证</li>
                        </ul>
                    </div>

                    <div class="mt-4">
                        <button type="submit" class="btn btn-primary">完成注册</button>
                        <a href="{% url 'login' %}" class="btn btn-outline-secondary ms-2">返回登录</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %} 